//index.js
//获取应用实例
const app = getApp()

Page({
  data: {    
    aps: [], //小区列表
    currAid: null, // 当前小区ID
    currAname: null, // 当前小区名称
    currDis: null, // 当前小区所在区县
    pros: [], // 商品数据列表
    unpayId: null, // 未支付订单ID
    width: null, // 屏幕宽度
  },
  // 获取数据
  getData: function (aid) {
    var that = this;
    var url = app.globalData.baseUrl + 'home/list';
    if (aid) {
      url += '/' + aid;
    }
    wx.request({
      url: url,
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        var code = res.data.errorcode;
        if (code == app.globalData.success) {          
          that.setData({
            aps: res.data.data.aps,
            currAid: res.data.data.currAid,
            currAname: res.data.data.currAname,
            currDis: res.data.data.currDis,
            pros: res.data.data.pros,
            unpayId: res.data.data.unpayId,
          });
        } else {
          wx.showToast({
            title: res.data.info,
          });
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '服务开小差，请稍后再试！',
        });
      },
      complete: function (res) {
        wx.hideLoading();
      },
    })
  },
  // 加载
  onLoad: function () {
    wx.showLoading({
      title: '加载中...',
    });
    var that = this;
    wx.getSystemInfo({
      success: function (res) {    
        that.setData({
          width: res.windowWidth,
        });
      },
    })
    that.getData();    
  }, 
  // 详情
  detail: function(e){
    var mid = e.currentTarget.dataset.mid;
    var pid = e.currentTarget.dataset.pid;   
    wx.navigateTo({
      url: '../product/product?mid=' + mid + '&pid='+pid ,
    })
  }, 
})
